package com.charmzenus.smallshop.controller;

import com.charmzenus.smallshop.base.SuccessInfo;
import com.charmzenus.smallshop.bean.UserBean;
import com.charmzenus.smallshop.bean.index.TestInfo;
import com.charmzenus.smallshop.service.IRedisService;
import com.charmzenus.smallshop.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    IRedisService redisService;

    @Autowired
    IUserService userService;

    private Logger logger = LoggerFactory.getLogger(IndexController.class);

    @RequestMapping("index/{name}")
    public SuccessInfo<TestInfo> index(@PathVariable String name) {

        TestInfo testInfo = new TestInfo();
        testInfo.username = name;

        redisService.put("token1", "hello", testInfo.toString(), 3600);

        logger.info(testInfo.toString());

        return new SuccessInfo<>(testInfo);
    }

    @RequestMapping("test")
    public UserBean test() {
        return userService.test();
    }

    @RequestMapping("test1")
    public String test1() {
        userService.addUser();
        return "success";
    }
}
